<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旋转动画效果</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .container {
            text-align: center;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            max-width: 500px;
            width: 100%;
        }

        .demo-box {
            width: 200px;
            height: 200px;
            margin: 20px auto;
            background-color: #9C27B0;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            border-radius: 8px;
            transition: transform 0.3s;
        }

        .controls {
            margin-top: 20px;
        }

        button {
            padding: 10px 20px;
            margin: 0 10px;
            border: none;
            border-radius: 4px;
            background-color: #2196F3;
            color: white;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #0b7dda;
        }

        .spin {
            animation: spin 2s linear infinite;
        }

        .pulse-rotate {
            animation: pulseRotate 2s ease-in-out infinite;
        }

        .rotate-once {
            animation: spin 1s ease-out forwards;
        }

        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        @keyframes pulseRotate {
            0% { transform: rotate(0deg) scale(1); }
            50% { transform: rotate(180deg) scale(1.2); }
            100% { transform: rotate(360deg) scale(1); }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>旋转动画效果</h1>
        <div class="demo-box" id="demoBox">旋转效果</div>
        <div class="controls">
            <button onclick="spin()">无限旋转</button>
            <button onclick="pulseRotate()">脉冲旋转</button>
            <button onclick="rotateOnce()">旋转一周</button>
            <button onclick="resetAnimation()">重置</button>
        </div>
        <div class="code-section">
            <h3>CSS代码:</h3>
            <pre><code>.spin {
  animation: spin 2s linear infinite;
}

.pulse-rotate {
  animation: pulseRotate 2s ease-in-out infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulseRotate {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}</code></pre>
        </div>
    </div>

    <script>
        const box = document.getElementById('demoBox');

        function spin() {
            resetAnimation();
            box.classList.add('spin');
        }

        function pulseRotate() {
            resetAnimation();
            box.classList.add('pulse-rotate');
        }

        function rotateOnce() {
            resetAnimation();
            box.classList.add('rotate-once');
        }

        function resetAnimation() {
            box.classList.remove('spin', 'pulse-rotate', 'rotate-once');
            // 触发重绘
            void box.offsetWidth;
        }
    </script>
</body>
</html>